package com.example.weight.greenSeasons.waterDeal;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import com.android.volley.AuthFailureError;
import com.android.volley.DefaultRetryPolicy;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import com.example.weight.R;
import com.example.weight.config.Config;
import com.hjq.bar.OnTitleBarListener;
import com.hjq.bar.TitleBar;

import net.cachapa.expandablelayout.ExpandableLayout;

import org.json.JSONException;
import org.json.JSONObject;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class BackwashTable_old extends AppCompatActivity {

    private TitleBar titleBar;
    private ExpandableLayout mozujian1;
    private Button ButtonNo1;
    private ExpandableLayout mozujian2;
    private Button ButtonNo2;
    private ExpandableLayout mozujian3;
    private Button ButtonNo3;
    private String factory;

    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");// HH:mm:ss
    private TextView tvImplementDate, tvRunTime1, tvRunTime2, tvRunTime3;
    private Button btnOpen1, btnClose1, btnOpen2, btnClose2, btnOpen3, btnClose3, btnSave;
    private EditText etTemperature, etDose, etWaterAmount, etRemarks;
//    private CheckBox cbFlow1, cbFlow2, cbFlow3, cbIsFive;
    private RadioButton rbYes1, rbYes2, rbYes3, rbYes4, rbNo1, rbNo2, rbNo3, rbNo4;
    private Spinner spMedicine, spSpecification;
    private List<String> medicineList, specificationList;
    private String medicineStr, specificationStr;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_backwash_table_old);

        Intent previousIntent = getIntent();
        factory = previousIntent.getStringExtra("factory");

        titleBar=findViewById(R.id.titleBar);
        tvImplementDate = findViewById(R.id.tvImplementDate);
        tvImplementDate.setText(simpleDateFormat.format(new Date()));

        tvRunTime1 = findViewById(R.id.tvRunTime1);
        tvRunTime2 = findViewById(R.id.tvRunTime2);
        tvRunTime3 = findViewById(R.id.tvRunTime3);

        btnOpen1 = findViewById(R.id.btnOpen1);
        btnClose1 = findViewById(R.id.btnClose1);
        btnOpen2 = findViewById(R.id.btnOpen2);
        btnClose2 = findViewById(R.id.btnClose2);
        btnOpen3 = findViewById(R.id.btnOpen3);
        btnClose3 = findViewById(R.id.btnClose3);
        btnSave = findViewById(R.id.btnSave);

//        etRemarks1 = findViewById(R.id.etRemarks1);
//        etRemarks2 = findViewById(R.id.etRemarks2);
//        etRemarks3 = findViewById(R.id.etRemarks3);
        etTemperature = findViewById(R.id.etTemperature);
//        etRemarksTemperature = findViewById(R.id.etRemarksTemperature);
        etDose = findViewById(R.id.etDose);
        etWaterAmount = findViewById(R.id.etWaterAmount);
        etRemarks = findViewById(R.id.etRemarks);

//        cbFlow1 = findViewById(R.id.cbFlow1);
//        cbFlow2 = findViewById(R.id.cbFlow2);
//        cbFlow3 = findViewById(R.id.cbFlow3);
//        cbIsFive = findViewById(R.id.cbIsFive);
        rbYes1 = findViewById(R.id.rbYes1);
        rbYes2 = findViewById(R.id.rbYes2);
        rbYes3 = findViewById(R.id.rbYes3);
        rbYes4 = findViewById(R.id.rbYes4);
        rbNo1 = findViewById(R.id.rbNo1);
        rbNo2 = findViewById(R.id.rbNo2);
        rbNo3 = findViewById(R.id.rbNo3);
        rbNo4 = findViewById(R.id.rbNo4);

        getInfo();

        spMedicine = findViewById(R.id.spMedicine);
        spSpecification = findViewById(R.id.spSpecification);

        medicineList = new ArrayList<>(Arrays.asList("盐酸", "次氯酸钠"));
        specificationList = new ArrayList<>(Arrays.asList("主要成分：盐酸，工业级含量30%，配置浓度1.25vol%", "主要成分:次氯酸根,工业级 (以有效氯计)含量 10%。配置浓度500mg/L"));

        ArrayAdapter<String> medicineAdapter = new ArrayAdapter<>(BackwashTable_old.this, android.R.layout.simple_spinner_item, medicineList);
        spMedicine.setAdapter(medicineAdapter);
        spMedicine.setSelection(0,true);
        medicineStr = medicineList.get(0);
        spMedicine.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                spSpecification.setSelection(position, true);
                medicineStr = medicineList.get(position);
                Toast.makeText(BackwashTable_old.this, medicineStr, Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });

        ArrayAdapter<String> specificationAdapter = new ArrayAdapter<>(BackwashTable_old.this, R.layout.custom_spinner_item, specificationList);
        specificationAdapter.setDropDownViewResource(R.layout.custom_spinner_item);
        spSpecification.setAdapter(specificationAdapter);
        spSpecification.setSelection(0,true);
        specificationStr = specificationList.get(0);
        spSpecification.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                spMedicine.setSelection(position, true);
                specificationStr = specificationList.get(position);
                Toast.makeText(BackwashTable_old.this, specificationStr, Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });

        Register();

        titleBar.setOnTitleBarListener(new OnTitleBarListener() {

            @Override
            public void onLeftClick(View v) {
                BackwashTable_old.this.finish();
            }

            @Override
            public void onTitleClick(View v) {

            }

            @Override
            public void onRightClick(View v) {

            }


        });
        mozujian1=findViewById(R.id.expandable_1);
        ButtonNo1=findViewById(R.id.button821);
        mozujian2=findViewById(R.id.expandable_2);
        ButtonNo2=findViewById(R.id.button822);
        mozujian3=findViewById(R.id.expandable_3);
        ButtonNo3=findViewById(R.id.button823);
    }

    public void showMozujian1(View view) {
        if (mozujian1.isExpanded()){
            ButtonNo1.setText("+ 1#膜组件");
        }else{
            ButtonNo1.setText("- 1#膜组件");
        }
        mozujian1.toggle();
    }

    public void showMozujian2(View view) {
        if (mozujian2.isExpanded()){
            ButtonNo2.setText("+ 2#膜组件");
        }else{
            ButtonNo2.setText("- 2#膜组件");
        }
        mozujian2.toggle();
    }

    public void showMozujian3(View view) {
        if (mozujian3.isExpanded()){
            ButtonNo3.setText("+ 3#膜组件");
        }else{
            ButtonNo3.setText("- 3#膜组件");
        }
        mozujian3.toggle();
    }

    public void getInfo(){
        RequestQueue queue = Volley.newRequestQueue(this);
        String url = Config.url + "/sjq/SjqWaterProductionBackwashing/getruntime1" + "?factory=" + factory;
        String url1 = Config.url + "/sjq/SjqWaterProductionBackwashing/getruntime2" + "?factory=" + factory;
        String url2 = Config.url + "/sjq/SjqWaterProductionBackwashing/getruntime3" + "?factory=" + factory;
        StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        try {
                            JSONObject jsonObject = new JSONObject(response);
//                            JSONArray datas = jsonObject.getJSONArray("data");
                            if (!jsonObject.isNull("data")) {
//                                for(int i=0;i<datas.length();i++){
//                                JSONObject data = jsonObject.getJSONObject("data");
                                String data = jsonObject.getString("data");
                                tvRunTime1.setText("反洗泵运行时间(min): "+data);
                                Log.d("zjy", data.toString());
                                //                                }
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                Toast.makeText(BackwashTable_old.this,
                        "暂无设备信息 " + error.getMessage(), Toast.LENGTH_SHORT).show();
            }
        });
        StringRequest stringRequest1 = new StringRequest(Request.Method.GET, url1,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        try {
                            JSONObject jsonObject = new JSONObject(response);
//                            JSONArray datas = jsonObject.getJSONArray("data");
                            if (!jsonObject.isNull("data")) {
//                                for(int i=0;i<datas.length();i++){
                                String data = jsonObject.getString("data");
                                tvRunTime2.setText("反洗泵运行时间(min): "+data);
                                //                                }
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                Toast.makeText(BackwashTable_old.this,
                        "暂无设备信息 " + error.getMessage(), Toast.LENGTH_SHORT).show();
            }
        });
        StringRequest stringRequest2 = new StringRequest(Request.Method.GET, url2,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        try {
                            JSONObject jsonObject = new JSONObject(response);
                            if (!jsonObject.isNull("data")) {
                                String data = jsonObject.getString("data");
                                tvRunTime3.setText("反洗泵运行时间(min): "+data);
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                Toast.makeText(BackwashTable_old.this,
                        "暂无设备信息 " + error.getMessage(), Toast.LENGTH_SHORT).show();
            }
        });
        stringRequest.setRetryPolicy(new DefaultRetryPolicy(10 * 1000,
                DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
        queue.add(stringRequest);
        queue.add(stringRequest1);
        queue.add(stringRequest2);
    }

    public void save(View view) {
        if (medicineStr.equals("")) {
            Toast.makeText(this, "Please choose medicine name", Toast.LENGTH_SHORT).show();
            return;
        }
        if(specificationStr.equals("")) {
            Toast.makeText(this, "Please choose medicine specification", Toast.LENGTH_SHORT).show();
            return;
        }
        if(etTemperature.getText().toString().equals("")) {
            Toast.makeText(this, "请填写水温实测值", Toast.LENGTH_SHORT).show();
            return;
        }
        if(etDose.getText().toString().equals("")) {
            Toast.makeText(this, "请填写药剂量", Toast.LENGTH_SHORT).show();
            return;
        }
        if(etWaterAmount.getText().toString().equals("")) {
            Toast.makeText(this, "请填写加水量", Toast.LENGTH_SHORT).show();
            return;
        }
//        if(etRemarks.getText().toString().equals("")) {
//            Toast.makeText(this, "请填写备注", Toast.LENGTH_SHORT).show();
//            return;
//        }

        new AlertDialog.Builder(this)
                .setTitle("确定保存吗？")
                .setCancelable(false)
                .setNegativeButton("取消", ((dialog, which) ->
                        Toast.makeText(this, "取消保存", Toast.LENGTH_SHORT).show()))
                .setPositiveButton("确定", (dialog, which) -> {
                    //提交请求
                    RequestQueue queue = Volley.newRequestQueue(this);
                    String url = Config.url + "/sjq/SjqWaterProductionBackwashing/addinfo";
                    StringRequest stringRequest = new StringRequest(Request.Method.POST, url,
                            new Response.Listener<String>() {
                                @Override
                                public void onResponse(String response) {
                                    try {
                                        JSONObject jsonObject = new JSONObject(response);
                                        String code = jsonObject.getString("code");
                                        if (code.startsWith("2")){
                                            Toast.makeText(BackwashTable_old.this,
                                                    "保存成功", Toast.LENGTH_SHORT).show();
                                        }
                                        else
                                            Toast.makeText(BackwashTable_old.this,
                                                    "保存失败", Toast.LENGTH_SHORT).show();
                                    } catch (JSONException e) {
                                        e.printStackTrace();
                                    }
                                }
                            }, new Response.ErrorListener() {
                        @Override
                        public void onErrorResponse(VolleyError error) {
                            Toast.makeText(BackwashTable_old.this, "保存失败", Toast.LENGTH_SHORT).show();
                            Log.d("LB", error.toString());
                        }
                    }) {
                        @Override
                        protected Map<String, String> getParams() throws AuthFailureError {
                            Map<String, String> map=new HashMap<>();
                            map.put("drug_name", medicineStr);
                            map.put("drug_specifications", specificationStr);
                            map.put("drug_dosage", etDose.getText().toString());
                            map.put("add_water", etWaterAmount.getText().toString());
                            map.put("remarks", etRemarks.getText().toString());
                            map.put("factory", factory);
                            return map;
                        }
                    };
                    stringRequest.setRetryPolicy(new DefaultRetryPolicy(10 * 1000,
                            DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
                    queue.add(stringRequest);
                    queue.add(addValue());
                })
                .show();
    }

    public StringRequest addValue(){
        String url = Config.url + "/sjq/SjqWaterProductionBackwashing/addvalue";
        return new StringRequest(Request.Method.POST, url,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        try {
                            JSONObject jsonObject = new JSONObject(response);
                            String code = jsonObject.getString("code");
                            if (code.startsWith("2")){
                                Toast.makeText(BackwashTable_old.this,
                                        "保存成功", Toast.LENGTH_SHORT).show();
                            }
                            else
                                Toast.makeText(BackwashTable_old.this,
                                        "保存失败", Toast.LENGTH_SHORT).show();
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                Toast.makeText(BackwashTable_old.this, "保存失败", Toast.LENGTH_SHORT).show();
                Log.d("LB", error.toString());
            }
        }) {
            @Override
            protected Map<String, String> getParams() throws AuthFailureError {
                Map<String, String> map=new HashMap<>();
                map.put("value", etTemperature.getText().toString());
                map.put("factory", factory);
                return map;
            }
        };
    }

    public void Register(){
        rbYes1.setOnClickListener(v -> {
            if (rbYes1.isChecked()){
                buildMyDialog(2);
            }
        });
        rbYes2.setOnClickListener(v -> {
            if (rbYes2.isChecked()){
                buildMyDialog(6);
            }
        });
        rbYes3.setOnClickListener(v -> {
            if (rbYes3.isChecked()){
                buildMyDialog(10);
            }
        });
        rbYes4.setOnClickListener(v -> {
            if (rbYes4.isChecked()){
                buildMyDialog(12);
            }
        });
        rbNo1.setOnClickListener(v -> {
            if(rbNo1.isChecked()){
                buildMyDialog(3);
            }
        });
        rbNo2.setOnClickListener(v -> {
            if(rbNo2.isChecked()){
                buildMyDialog(7);
            }
        });
        rbNo3.setOnClickListener(v -> {
            if(rbNo3.isChecked()){
                buildMyDialog(11);
            }
        });
        rbNo4.setOnClickListener(v -> {
            if(rbNo4.isChecked()){
                buildMyDialog(13);
            }
        });
        btnOpen1.setOnClickListener(v -> {
            buildMyDialog(0);
        });
        btnOpen2.setOnClickListener(v -> {
            buildMyDialog(4);
        });
        btnOpen3.setOnClickListener(v -> {
            buildMyDialog(8);
        });
        btnClose1.setOnClickListener(v -> {
            buildMyDialog(1);
        });
        btnClose2.setOnClickListener(v -> {
            buildMyDialog(5);
        });
        btnClose3.setOnClickListener(v -> {
            buildMyDialog(9);
        });
    }

    private void buildMyDialog(Integer index){
        //when "是" radiobutton selected
        if(index == 3 || index == 7 || index == 11 || index == 13 || index == 2 || index == 6
                || index ==10 || index == 12 ){
            View view = LayoutInflater.from(BackwashTable_old.this).inflate(R.layout.layout_remarks_dialog,null);
            EditText etUserName = view.findViewById(R.id.et_notice);
            Button btnLogin = view.findViewById(R.id.btn_save_notice);
            MyDialog remakrsDialog = new MyDialog(BackwashTable_old.this);
            remakrsDialog.setTitle("若选择是，请直接提交；若选择否，请填写备注后再提交");
            remakrsDialog.setView(view);
            btnLogin.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    new AlertDialog.Builder(BackwashTable_old.this)
                            .setTitle("确定保存吗？")
                            .setCancelable(false)
                            .setNegativeButton("取消", ((dialog, which) ->
                                    Toast.makeText(BackwashTable_old.this, "取消保存", Toast.LENGTH_SHORT).show()))
                            .setPositiveButton("确定", (dialog, which) -> {
                                // 提交表单
                                RequestQueue queue = Volley.newRequestQueue(BackwashTable_old.this);
                                String choiceUrl = "";
                                String YN = "false";
                                String buttonId = "-1";
                                switch (index){
                                    //否
                                    case 3:
                                        choiceUrl = "/sjq/SjqWaterProductionBackwashing/addisfive1";
                                        buttonId = "2";
                                        break;
                                    case 7:
                                        choiceUrl = "/sjq/SjqWaterProductionBackwashing/addisfive2";
                                        buttonId = "5";
                                        break;
                                    case 11:
                                        choiceUrl = "/sjq/SjqWaterProductionBackwashing/addisfive3";
                                        buttonId = "8";
                                        break;
                                    case 13:
                                        buttonId = "9";
                                        choiceUrl = "/sjq/SjqWaterProductionBackwashing/addisfive4";
                                        break;

                                    //是
                                    case 2:
                                        choiceUrl = "/sjq/SjqWaterProductionBackwashing/addisfive1";
                                        buttonId = "2";
                                        YN = "true";
                                        break;
                                    case 6:
                                        choiceUrl = "/sjq/SjqWaterProductionBackwashing/addisfive2";
                                        buttonId = "5";
                                        YN = "true";
                                        break;
                                    case 10:
                                        choiceUrl = "/sjq/SjqWaterProductionBackwashing/addisfive3";
                                        buttonId = "8";
                                        YN = "true";
                                        break;
                                    case 12:
                                        choiceUrl = "/sjq/SjqWaterProductionBackwashing/addisfive4";
                                        buttonId = "9";
                                        YN = "true";
                                        break;
                                }
                                String url = Config.url + choiceUrl;

                                String finalYN = YN;
                                String finalButtonId = buttonId;
                                StringRequest stringRequest = new StringRequest(Request.Method.POST, url,
                                        new Response.Listener<String>() {
                                            @Override
                                            public void onResponse(String response) {
                                                try {
                                                    JSONObject jsonObject = new JSONObject(response);
                                                    String code = jsonObject.getString("code");

                                                    if (code.startsWith("2"))
                                                        Toast.makeText(BackwashTable_old.this,
                                                                "提交成功", Toast.LENGTH_SHORT).show();
                                                    else
                                                        Toast.makeText(BackwashTable_old.this,
                                                                "提交失败", Toast.LENGTH_SHORT).show();
                                                } catch (JSONException e) {
                                                    e.printStackTrace();
                                                }
                                            }
                                        }, new Response.ErrorListener() {
                                    @Override
                                    public void onErrorResponse(VolleyError error) {
                                        Toast.makeText(BackwashTable_old.this,
                                                "保存失败 " + error.getMessage(), Toast.LENGTH_SHORT).show();
                                    }
                                }) {
                                    @Override
                                    protected Map<String, String> getParams() {
                                        Map<String, String> map=new HashMap<>();
                                    map.put("num", finalButtonId);
                                    map.put("yn", finalYN);
                                    map.put("reason", etUserName.getText().toString());
//                                  map.put("examiner", getIntent().getStringExtra("name"));
                                    map.put("factory", factory);
                                    return map;
                                    }
                                };
                                remakrsDialog.dismiss();
                                stringRequest.setRetryPolicy(new DefaultRetryPolicy(10 * 1000,
                                        DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
                                queue.add(stringRequest);
//                            recordHandler.sendEmptyMessageDelayed(0, 500);
                            })
                            .show();
//                dialog.dismiss();
                }
            });
            remakrsDialog.show();
        }else if(index == 0 || index == 1 || index == 4 || index == 5 || index ==8 || index ==9 ){
            //when machine switch button push
            new AlertDialog.Builder(BackwashTable_old.this)
                    .setTitle("确定提交吗？")
                    .setCancelable(false)
                    .setNegativeButton("取消", ((dialog, which) ->
                            Toast.makeText(BackwashTable_old.this, "取消保存", Toast.LENGTH_SHORT).show()))
                    .setPositiveButton("确定", (dialog, which) -> {
                        // 提交表单
                        RequestQueue queue = Volley.newRequestQueue(BackwashTable_old.this);
                        String choiceUrl = "";
                        String buttonId = "-1";
                        switch(index){
                            case 0:
                                choiceUrl="/sjq/SjqWaterProductionBackwashing/addontime1";
                                buttonId = index.toString();
                                break;
                            case 1:
                                choiceUrl="/sjq/SjqWaterProductionBackwashing/addofftime1";
                                buttonId = "1";
                                buttonId = index.toString();
                                break;
                            case 4:
                                choiceUrl="/sjq/SjqWaterProductionBackwashing/addontime2";
                                buttonId = "3";
                                break;
                            case 5:
                                choiceUrl="/sjq/SjqWaterProductionBackwashing/addofftime2";
                                buttonId = "4";
                                break;
                            case 8:
                                choiceUrl="/sjq/SjqWaterProductionBackwashing/addontime3";
                                buttonId = "6";
                                break;
                            case 9:
                                choiceUrl="/sjq/SjqWaterProductionBackwashing/addofftime3";
                                buttonId = "7";
                                break;
                        }
                        String url = Config.url + choiceUrl;

                        String finalButtonId = buttonId;
                        StringRequest stringRequest = new StringRequest(Request.Method.POST, url,
                                new Response.Listener<String>() {
                                    @Override
                                    public void onResponse(String response) {
                                        Log.d("syjc", response);
                                        try {
                                            JSONObject jsonObject = new JSONObject(response);
                                            String code = jsonObject.getString("code");

                                            if (code.startsWith("2"))
                                                Toast.makeText(BackwashTable_old.this,
                                                        "提交成功", Toast.LENGTH_SHORT).show();
                                            else
                                                Toast.makeText(BackwashTable_old.this,
                                                        "提交失败", Toast.LENGTH_SHORT).show();
                                        } catch (JSONException e) {
                                            e.printStackTrace();
                                        }
                                    }
                                }, new Response.ErrorListener() {
                            @Override
                            public void onErrorResponse(VolleyError error) {
                                Toast.makeText(BackwashTable_old.this,
                                        "保存失败 " + error.getMessage(), Toast.LENGTH_SHORT).show();
                            }
                        }) {
                            @Override
                            protected Map<String, String> getParams() {
                                Map<String, String> map=new HashMap<>();
//                                    map.put("shift", currentShift);
//                                    map.put("equipment_name", currentEquip);
                                map.put("num", finalButtonId);
//                                    map.put("examiner", getIntent().getStringExtra("name"));
                                map.put("factory", factory);
                                return map;
                            }
                        };
//                        remakrsDialog.dismiss();
                        stringRequest.setRetryPolicy(new DefaultRetryPolicy(10 * 1000,
                                DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
                        queue.add(stringRequest);
//                            recordHandler.sendEmptyMessageDelayed(0, 500);
                    })
                    .show();
        }
    }

    static class MyDialog extends AlertDialog {

        public MyDialog(@NonNull Context context) {
            super(context);
        }
    }
}